package com.chenshang.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class FileReaderUtil {
	public static final Logger LOGGER = (Logger) LoggerFactory.getLogger(FileReaderUtil.class);

	public static String readFileToString(File file) {

		StringBuffer sb = new StringBuffer();
		try {
			FileInputStream inputStream = new FileInputStream(file);
			@SuppressWarnings("resource")
			BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "utf-8"));
			String line = "";
			while ((line = bufferedReader.readLine()) != null) {
				sb.append(line);
			}
		} catch (IOException e) {
			e.printStackTrace();
			LOGGER.info("读取文件内容异常");
		}
		return sb.toString();
	}

	public static String readFileToString(String path) {
		return readFileToString(new File(path));
	}

}
